'''
timeout：超时设置
1.接口响应时间较久，默认的时间内返回不了，通过timeout设置大一点的超时时间
    比如上传大的文件
2.测试接口的性能，看是否能在规定的某个时间内返回
'''
import requests
# 淘宝查询手机号归属地的接口
# url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel =19914668119"
# for i in range(10):
#     r = requests.get(url ,timeout=0.1)# 20ms
#     # Connection to tcc.taobao.com timed out. 超时报错
#     print(r.text)


'''
设置代理
1.通过界面操作某个功能正常，但是通过接口操作某个功能不正常
    分别抓取界面、自动化的包，对比差异。
2.通过同一个IP频繁访问某个地址，可能会被服务器屏蔽掉，设置代理，
    发出去的请求，显示代理的地址
'''

proxy={
    #协议：代理地址
    "http":"http://127.0.0.1:8888",
    "https":"http://127.0.0.1:8888"
}
# r = requests.get("http://www.baidu.com",proxies=proxy) # 需打开fiddler
# print(r.text)
# # unable to get local issuer certificate
# # 可以设置部校验证书
# r = requests.get("http://www.baidu.com",proxies=proxy,verify=False)
# print(r.text)
# 注册接口自动化
# s= requests.Session()
# url = "http://192.168.150.84:8888/futureloan/mvc/api/member/register"
# cs = {"Mobilephone":'1111111111',
#       "pwd":'1234567',
#       "regname":" "}
# r = s.post(url,data=cs)
# print(r.text)
s = requests.Session()
url = "http://192.168.150.84:8088/futureloan/mvc/api/member/register"
cs = {
"mobilephone":"1234567890",
"pwd":"12345",
"regname"	:" "
}
r= s.post(url,data=cs)
print(r.text,"密码长度5位")
print("==================================注册===========================================")

cs = {
"mobilephone":	"1234567890",
"pwd":"1111111111111111111",
"regname"	:" "
}
r= s.post(url,data=cs)
print(r.text,"密码长度19位")
print("==================================注册===========================================")

cs = {
"mobilephone":	"1234567890",
"pwd":"123456",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"手机号码格式：1234567890")

cs = {
"mobilephone":	"1881234567",
"pwd":"123456",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"手机号码长度10位")
print("==================================注册===========================================")
cs = {
"mobilephone":	"188123456744",
"pwd":"123456",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"手机号码长度12位")
print("==================================注册===========================================")

cs = {
"mobilephone":	"18812345678",
"pwd":"123456",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"手机号已注册")
print("==================================注册===========================================")

cs = {
"mobilephone":	"",
"pwd":"123456",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text)
print("==================================注册===========================================")

cs = {
"mobilephone":	"*1311919802",
"pwd":"123456",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"手机号开头含有*")
print("==================================注册===========================================")

cs = {
"mobilephone":	"1311919802*",
"pwd":"123456",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"手机号结尾含有*")
print("==================================注册===========================================")

cs = {
"mobilephone":	"13119*19802",
"pwd":"123456",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"手机号中间含有*")
print("==================================注册===========================================")

cs = {
"mobilephone":	"_1311919802",
"pwd":"123456",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"手机号开头含有_")
print("==================================注册===========================================")

cs = {
"mobilephone":	"13119219802",
"pwd":"",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"密码为空")
print("==================================注册===========================================")

cs = {
"mobilephone":	"13119519802",
"pwd":"123456*#￥%#%￥#",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text,"密码含有*等特殊字符")
print("==================================注册===========================================")

cs = {
"mobilephone":	"13119519802",
"pwd":"123456",
"regname"	:""}
r= s.post(url,data=cs)
print(r.text)
print("==================================注册===========================================")
cs = {
"mobilephone":	"13119519822",
"pwd":"1234 56_",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text)
print("==================================注册===========================================")
cs = {
"mobilephone":	"13119519823",
"pwd":"1234 56_",
"regname":"lisahddhlidliadjlsdjjjihahdjalidjwlijisjaliwjdlijslijlifalijfdsojaijflihslijliadahflihsalijliajdiwhliahsfiusjlidajldhkjsahfkwahflihfslidlawhdksakakfks"}
r= s.post(url,data=cs)
print(r.text,"用户名超长")
print("==================================注册===========================================")

cs = {
"mobilephone":	"13119519844",
"pwd":" "}
r= s.post(url,data=cs)
print(r.text)
print("==================================注册===========================================")

cs = {
"mobilephone":	"13119519839",
"pwd":"带娃来得及垃圾的",
"regname"	:" "}
r= s.post(url,data=cs)
print(r.text)
print("==================================注册===========================================")


